package com.itheima.mapdemo;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class MapDemo2 {
    public static void main(String[] args) {
        HashMap<String, String> map = new HashMap<>();
        map.put("帅帅的MR.Z", "三玖");
        map.put("帅的MR.Z", "阿卡丽");
        map.put("帅帅帅的MR.Z", "阿狸");
        map.put("非常帅的MR.Z", "Seraphine");
        map.put("无敌帅的MR.Z", "D.VA");

        //System.out.println(map);
//          使用迭代器或者增强for循环
        Set<String> keys = map.keySet();
        for (String key : keys) {
            String value = map.get(key);
            System.out.println(key + "❤" + value);
        }
        System.out.println("=======================");
        Iterator<String> it = keys.iterator();
        while (it.hasNext()) {
            String s = it.next();
            String v = map.get(s);
            System.out.println(s + "❤" + v);

        }
        System.out.println("=======================");
        //获取Map集合中所有的键值对象
        Set<Map.Entry<String,String>>entries = map.entrySet();
        //遍历set集合
        for (Map.Entry<String,String>entry:entries){
            String key = entry.getKey();
            String value = entry.getValue();
            System.out.println(key + "❤" + value);
        }
        System.out.println("=======================");
        //迭代器遍历
        Iterator<Map.Entry<String, String>> it2 = entries.iterator();
        while (it2.hasNext()){
            Map.Entry s1 = it2.next();
         //   String v1 = map.get(s1);
          //  System.out.println(s1 + "❤" + v1);

        }


    }
}
